﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;
using HF.BizWinner.DB.Linq;

namespace HF.BizWinner.DB.Authority
{
    public enum AuthorityType
    {
        Pass,
        Reject,
        NoPage,
        LoginError
    }

    public class UserAuthority
    {
        public static User GetLoginUser()
        {
            HttpSessionState Session = HttpContext.Current.Session;
            object user = Session["USER"];
            return user == null ? null : (User)user;
        }

        public static void SetLoginUser(User user)
        {
            HttpSessionState Session = HttpContext.Current.Session;
            Session["USER"] = user;
        }

        public static void Logout()
        {
            HttpSessionState Session = HttpContext.Current.Session;
            Session["USER"] = null;
            Session.Remove("USER");
        }

        public static void SetAuthorityMessage(string msg)
        {
            HttpSessionState Session = HttpContext.Current.Session;
            Session["AuthorityMessage"] = msg;
        }

        public static string GetAuthorityMessage()
        {
            HttpSessionState Session = HttpContext.Current.Session;
            object msg = Session["AuthorityMessage"];
            return msg == null ? string.Empty : msg.ToString();
        }

        /// <summary>
        /// 取得所请求页面的文件名称
        /// </summary>
        public static string RequestFileName
        {
            get
            {
                // 取得所请求页面的文件名称
                string aspxFileName = HttpContext.Current.Request.ServerVariables["PATH_TRANSLATED"];
                FileInfo fileInfo = new FileInfo(aspxFileName);
                aspxFileName = fileInfo.Name;
                return aspxFileName;
            }
        }

        public UserAuthority()
        {
        }
    }
}
